package com.controller;
import com.pojo.RbacManager;
import com.pojo.RbacManagerDTO;
import com.pojo.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/rbacManager")
public class RbacManagerControl {
    @RequestMapping("/comeJson")
    public ModelAndView comeJson(@RequestBody RbacManagerDTO user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg", user);
        modelAndView.setViewName("index");
        return modelAndView;
    }

    //测试form表单
    @RequestMapping("/comeForm")
    public ModelAndView comeForm(String name){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg",name);
        modelAndView.setViewName("success");
        return modelAndView;
    }
    //返回String
    @RequestMapping("/returnString")
    public String returnString(Model model, String name){
        model.addAttribute("msg",name);
        return "success";
    }
    //返回obj
    @RequestMapping("returnObj")
    @ResponseBody
    public ResponseEntity returnObj(@RequestBody RbacManagerDTO rbacManager){
        ResponseEntity<RbacManager> rbacManagerResponseEntity = new ResponseEntity<>(200,"成功",rbacManager);
        return rbacManagerResponseEntity;
    }
    //重定向String
    @RequestMapping("testRedirect")
    public String testRedirect(){
        return "redirect:/rbacManager/returnString?name=123";
    }
    //转发String
    @RequestMapping("testForward")
    public String testForward(){
        return "forward://rbacManager/returnString?name=123";
    }
}
